<?php

class Mem
{
	protected static $ins=null;
	protected $host=null;
	protected $port=null;
	protected $_Mem=null;

	protected function __construct(){}

	public static function getIns()
	{
		if(self::$ins)
		{
			return self::$ins;
		}
		self::$ins=new self();
		//include(ROOT.'include/conf.class.php');
		$cfg=cfg::getIns();
		$mem=$cfg->mem;
		self::$ins->host=$mem['host'];
		self::$ins->port=$mem['port'];
		self::$ins->_Mem=new Memcache;
		self::$ins->_Mem->connect(self::$ins->host,self::$ins->port);
		return self::$ins;
	}
	
	public function add($k,$v,$t=0)
	{
		return $this->_Mem->add(strval($k),strval($v),MEMCACHE_COMPRESSED,$t);
	}
	public function get($k)
	{
		return $this->_Mem->get(strval($k));
	}
	public function replace($k,$v,$t=0)
	{
		$this->_Mem->replace(strval($k),strval($v),MEMCACHE_COMPRESSED,$t);
		return $this->_Mem->get(strval($k))==strval($v);
	}
	public function set($k,$v,$t=0)
	{
		//$this->_Mem->delete($k);
		$this->_Mem->set(strval($k),strval($v),MEMCACHE_COMPRESSED,$t);
		return $this->_Mem->get(strval($k))==strval($v);
	}
	public function del($k)
	{
		return $this->_Mem->delete(strval($k));
	}



	public function getStats($list='')
	{
		return $this->_Mem->getStats($list);
	}

	public function getExtendedStats($list='')
	{
		return $this->_Mem->getExtendedStats($list);
	}

	public function getVer()
	{
		return $this->_Mem->getVersion();
	}

	public function getAllKeys()
	{
		return $this->_Mem->getAllKeys();
	}
}